package com.ruoyi.petition.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.petition.domain.LegalClassroom;
import com.ruoyi.petition.service.ILegalClassroomService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 法制讲堂Controller
 *
 * @author ZWX
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/petition/legalClassroom")
@RequiredArgsConstructor
public class LegalClassroomController extends BaseController {
    private final ILegalClassroomService legalClassroomService;

    /**
     * 查询法制讲堂列表
     */
    @PreAuthorize("@ss.hasPermi('petition:legalClassroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(LegalClassroom legalClassroom) {
        startPage();
        List<LegalClassroom> list = legalClassroomService.selectLegalClassroomList(legalClassroom);
        return getDataTable(list);
    }

    /**
     * 导出法制讲堂列表
     */
    @PreAuthorize("@ss.hasPermi('petition:legalClassroom:export')")
    @Log(title = "法制讲堂", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LegalClassroom legalClassroom) {
        List<LegalClassroom> list = legalClassroomService.selectLegalClassroomList(legalClassroom);
        ExcelUtil<LegalClassroom> util = new ExcelUtil<LegalClassroom>(LegalClassroom.class);
        util.exportExcel(response, list, "法制讲堂数据");
    }

    /**
     * 获取法制讲堂详细信息
     */
    @PreAuthorize("@ss.hasPermi('petition:legalClassroom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(legalClassroomService.selectLegalClassroomById(id));
    }

    /**
     * 新增法制讲堂
     */
    @PreAuthorize("@ss.hasPermi('petition:legalClassroom:add')")
    @Log(title = "法制讲堂", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LegalClassroom legalClassroom) {
        return toAjax(legalClassroomService.insertLegalClassroom(legalClassroom));
    }

    /**
     * 修改法制讲堂
     */
    @PreAuthorize("@ss.hasPermi('petition:legalClassroom:edit')")
    @Log(title = "法制讲堂", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LegalClassroom legalClassroom) {
        return toAjax(legalClassroomService.updateLegalClassroom(legalClassroom));
    }

    /**
     * 删除法制讲堂
     */
    @PreAuthorize("@ss.hasPermi('petition:legalClassroom:remove')")
    @Log(title = "法制讲堂", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(legalClassroomService.deleteLegalClassroomByIds(ids));
    }
}
